package com.eurekaclient.controller;

import com.eurekaclient.entity.StudentEntity;
import com.eurekaclient.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @Value("${server.port}")
    private String post;
    @GetMapping("/all")
    public Collection<StudentEntity> all(){
        String a="1";
        return studentService.findAll();
    }
    @GetMapping("/Byid/{id}")
    public StudentEntity byId(@PathVariable("id")Long id){
        return studentService.findById(id);
    }
    @PostMapping("/save")
    public void save(@RequestBody StudentEntity studentEntity){
        studentService.saveOrUpdate(studentEntity);
    }
    @PutMapping("/update")
    public void update(@RequestBody StudentEntity studentEntity){
        studentService.saveOrUpdate(studentEntity);
    }
    @DeleteMapping("/del/{id}")
    public void del(@PathVariable("id")Long id){
        studentService.del(id);
    }

    @GetMapping("/index")
    public String index(){
        return "端口"+this.post;
    }
}
